package StackPractice;

//使用数组实现栈
public class ArrayStack {
    public int maxSize;
    public int[] arrayStack;
    public int top = -1;

    public ArrayStack(int maxSize) {
        this.maxSize = maxSize;
        arrayStack = new int[maxSize];
    }

    public Boolean isFull() {
        return top == maxSize - 1;
    }

    public Boolean isEmpty() {
        return top == -1;
    }

    public void add(int value) {
        if (isFull()) {
            return;
        }
        arrayStack[++top] = value;
    }

    public int pop(){
        if(isEmpty()){
            throw new RuntimeException("栈为空，无法出栈！");
        }
        int value = arrayStack[top--];
        return value;
    }

    public static void main(String[] args) {
        ArrayStack arrayStack = new ArrayStack(3);
        arrayStack.add(0);
        arrayStack.add(1);
        arrayStack.add(2);
        int pop = arrayStack.pop();
        System.out.println(pop);
    }
}
